package com.zn.web.rpc;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zn.util.Constant;
import com.zn.util.HttpClientUtil;
import com.zn.vo.AccountInfo;
import com.zn.vo.CustomerReportInfo;
import com.zn.vo.ReportResponse;
import com.zn.vo.Response;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.TimeZone;

/**
 * @author YinJiaWei
 * @version 2018/8/25 20:12
 */
@Component
public class TradeRemoteCall {
    private static final Logger LOGGER = LoggerFactory.getLogger(TradeRemoteCall.class);
    @Value("${jiejiari.url}")
    private String url;
    @Value("${jiejiari.interface.checkholiday}")
    private String checkHoliday;
    @Value("${totality.task.url}")
    private String totalityTaskUrl;
    private static final ObjectMapper MAPPER = new ObjectMapper();
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    static {
        MAPPER.setTimeZone(TimeZone.getTimeZone("GMT+8"));
    }
    public Response checkHoliday(String date){
        Response response = HttpClientUtil.post(url,
                HttpClientUtil.Builder.builder(checkHoliday)
                        .with("date", date)
        );
        return response;
    }

    /**
     * 查询机构代理账户信息接口
     * @param businessUnique
     * @return
     */
    public String getAgencyAccount(String businessUnique){
        try {
            String jsonResult=HttpClientUtil.post(HttpClientUtil.Builder.builder("/business/getAgencyAccount")
                    .with("businessUnique", businessUnique),totalityTaskUrl);
            return jsonResult;
        }catch (Exception e){
            LOGGER.error("getAgencyAccount..."+e);
            return "";
        }
    }
    public Response tradeCapitalChange(String businessUnique,String orderNo,String operationType,
                                       String version,String volume,Double operationCapital,Double operationFreezeCapital){
        Response response=new Response();
        try {
             response=HttpClientUtil.post(totalityTaskUrl,
                    HttpClientUtil.Builder.builder("/business/tradeCapitalChange")
                            .with("businessUnique", businessUnique)
                            .with("orderNo", orderNo)
                            .with("operationType", operationType)
                            .with("version",version)
                            .with("volume",volume)
                            .with("operationCapital",operationCapital)
                            .with("operationFreezeCapital",operationFreezeCapital)
            );
            return response;
        }catch (Exception e){
            LOGGER.error("tradeCapitalChange......"+e);
            return response;
        }
    }

    public void sendSocketStatus(String businessUnique,Integer listenerType,Integer socketStatus){
        try{
            HttpClientUtil.post(totalityTaskUrl,
                    HttpClientUtil.Builder.builder("/management/readSocketStatus")
                            .with("businessUnique", businessUnique)
                            .with("listenerType", listenerType)
                            .with("socketStatus", socketStatus)
            );
        }catch (Exception e){
            LOGGER.error("sendSocketStatus......"+e);
        }
    }
}
